package com.tunan.common;

import org.springframework.stereotype.Component;
import org.springframework.web.filter.CharacterEncodingFilter;

import com.tunan.common.filter.LoginFilter;

import javax.servlet.Filter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class FilterManager {

	private @Autowired AutowireCapableBeanFactory beanFactory;

	/**
	 * 
	 * @return FilterRegistrationBean
	 * @  编码过滤器，以UTF8编码
	 * @date 2016年3月23日
	 * @author kinda
	 */
	@Bean
	public FilterRegistrationBean encodeFilter3() {
		FilterRegistrationBean registration = new FilterRegistrationBean();
		CharacterEncodingFilter encodeFilter = new CharacterEncodingFilter();
		encodeFilter.setEncoding("UTF-8");
		beanFactory.autowireBean(encodeFilter);
		registration.setFilter(encodeFilter);
		registration.addUrlPatterns("/*");
		return registration;
	}

}
